package cn.jetpiece.cloud.system.dp.app.utils;


import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: dust-server
 * @ClassName: com.hckj.iot.dust.core.util.ErrorStackUtil
 * @Author: zdingxin
 * @Description: ErrorStackUtil
 * @Date: 2021/3/1
 * @Version: 1.0
 */
public class ErrorStackUtil {

    public static String getStackTrace(Throwable t) {
        StringBuilder builder = new StringBuilder();
        t = initialize(t);
        StackTraceElement[] trace = t.getStackTrace();
        StackTraceElement[] var3 = trace;
        int var4 = trace.length;

        for (int var5 = 0; var5 < var4; ++var5) {
            StackTraceElement stackTraceElement = var3[var5];
            builder.append("at " + stackTraceElement.getClassName() + "(" + stackTraceElement.getMethodName() + ":" + stackTraceElement.getLineNumber() + ")");
        }
        return builder.toString();
    }

    public static Throwable initialize(Throwable t) {
        StackTraceElement[] trace = t.getStackTrace();
        List<StackTraceElement> newTrace = new ArrayList();
        StackTraceElement[] clean = trace;
        int size = trace.length;
        for (int var5 = 0; var5 < size; ++var5) {
            StackTraceElement stackTraceElement = clean[var5];
            newTrace.add(stackTraceElement);
        }
        clean = new StackTraceElement[newTrace.size()];
        newTrace.toArray(clean);
        t.setStackTrace(clean);
        return t;
    }
}